var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
  return typeof e;
} : function (e) {
  return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
};

!function (e) {
  if ("object" == ("undefined" == typeof exports ? "undefined" : _typeof(exports)) && "undefined" != typeof module) module.exports = e();else if ("function" == typeof define && define.amd) define([], e);else {
    ("undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this).html2json = e();
  }
}(function () {
  var c = /^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,
      f = /^<\/([-A-Za-z0-9_]+)[^>]*>/,
      u = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g,
      p = e("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr"),
      h = e("a,address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video"),
      m = e("abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var"),
      b = e("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr"),
      g = e("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"),
      v = e("script,style"),
      t = function (e, i) {
    var t,
        n,
        r,
        a = [],
        o = e;

    for (a.last = function () {
      return this[this.length - 1];
    }; e;) {
      if (n = !0, a.last() && v[a.last()]) e = e.replace(new RegExp("([\\s\\S]*?)</" + a.last() + "[^>]*>"), function (e, t) {
        return t = t.replace(/<!--([\s\S]*?)-->|<!\[CDATA\[([\s\S]*?)]]>/g, "$1$2"), i.chars && i.chars(t), "";
      }), d("", a.last());else if (0 == e.indexOf("\x3c!--") ? 0 <= (t = e.indexOf("--\x3e")) && (i.comment && i.comment(e.substring(4, t)), e = e.substring(t + 3), n = !1) : 0 == e.indexOf("</") ? (r = e.match(f)) && (e = e.substring(r[0].length), r[0].replace(f, d), n = !1) : 0 == e.indexOf("<") && (r = e.match(c)) && (e = e.substring(r[0].length), r[0].replace(c, l), n = !1), n) {
        var s = (t = e.indexOf("<")) < 0 ? e : e.substring(0, t);
        e = t < 0 ? "" : e.substring(t), i.chars && i.chars(s);
      }
      if (e == o) throw "Parse Error: " + e;
      o = e;
    }

    function l(e, t, n, r) {
      if (t = t.toLowerCase(), h[t]) for (; a.last() && m[a.last()];) d("", a.last());

      if (b[t] && a.last() == t && d("", t), (r = p[t] || !!r) || a.push(t), i.start) {
        var o = [];
        n.replace(u, function (e, t) {
          var n = arguments[2] ? arguments[2] : arguments[3] ? arguments[3] : arguments[4] ? arguments[4] : g[t] ? t : "";
          o.push({
            name: t,
            value: n,
            escaped: n.replace(/(^|[^\\])"/g, '$1\\"')
          });
        }), i.start && i.start(t, o, r);
      }
    }

    function d(e, t) {
      if (t) for (n = a.length - 1; 0 <= n && a[n] != t; n--);else var n = 0;

      if (0 <= n) {
        for (var r = a.length - 1; n <= r; r--) i.end && i.end(a[r]);

        a.length = n;
      }
    }

    d();
  };

  function e(e) {
    for (var t = {}, n = e.split(","), r = 0; r < n.length; r++) t[n[r]] = !0;

    return t;
  }

  return function (e) {
    e = e.replace(/<\?xml.*\?>\n/, "").replace(/<!doctype.*\>\n/, "").replace(/<!DOCTYPE.*\>\n/, "");
    var i = [],
        a = {
      node: "root",
      child: []
    };
    return t(e, {
      start: function (e, t, n) {
        var r = {
          node: "element",
          tag: e
        };

        if (0 !== t.length && (r.attr = t.reduce(function (e, t) {
          var n = t.name,
              r = t.value;
          return e[n] ? Array.isArray(e[n]) ? e[n].push(r) : e[n] = [e[n], r] : e[n] = r, e;
        }, {})), n) {
          var o = i[0] || a;
          void 0 === o.child && (o.child = []), o.child.push(r);
        } else i.unshift(r);
      },
      end: function (e) {
        var t = i.shift();
        if (t.tag !== e && console.error("invalid state: mismatch end tag"), 0 === i.length) a.child.push(t);else {
          var n = i[0];
          void 0 === n.child && (n.child = []), n.child.push(t);
        }
      },
      chars: function (e) {
        var t = {
          node: "text",
          text: e
        };
        if (0 === i.length) a.child.push(t);else {
          var n = i[0];
          void 0 === n.child && (n.child = []), n.child.push(t);
        }
      },
      comment: function (e) {
        var t = {
          node: "comment",
          text: e
        },
            n = i[0];
        void 0 === n.child && (n.child = []), n.child.push(t);
      }
    }), a;
  };
});